<?php
spAddViewFunction('pager', '__template_pager');
function __template_pager($params){
	if( !isset($params['pager']) || empty($params['pager']) )return '';
	$args = array();
	foreach( $params as $k => $v )if( !in_array($k, array('c','a','pager','myclass','mypage')) )$args[$k] = $v;
	$pagerhandle = isset($params['pager']['mypage']) ? $params['pager']['mypage'] : 'page';
	$html = "<div class=\"{$params['myclass']}\">";
	if( $params['pager']['current_page'] != $params['pager']['first_page'] ){
		$url = spUrl($params['c'], $params['a'], $args + array($pagerhandle => $params['pager']['prev_page']));
		$html .= "<a href=\"{$url}\">上一页</a>";
	}else{
		$html .= "<span class=\"disabled\">上一页</span>";
	}
	foreach( $params['pager']['all_pages'] as $p ){
		if( $p == $params['pager']['current_page'] ){
			$html .= "<span class=\"current\">{$p}</span>";
		}else{
			$url = spUrl($params['c'], $params['a'], $args + array($pagerhandle => $p));
			$html .= "<a href=\"$url\">{$p}</a>";
		}
	}
	if( $params['pager']['current_page'] != $params['pager']['last_page'] ){
		$url = spUrl($params['c'], $params['a'], $args + array($pagerhandle => $params['pager']['next_page']));
		$html .= "<a href=\"$url\">下一页</a>";
	}else{
		$html .= "<span class=\"disabled\">下一页</span>";
	}
	$html .= '</div>';
	return $html;
}